﻿#include "object.h"

CObject::CObject(LPD3DXSPRITE SpriteHandler,float XHandle, float YHandle)
{
	_SpriteHandler = SpriteHandler;
	_last_time = 0;
	x_handle = XHandle;
	y_handle = YHandle;
	_vx = 0;
	_vy = 0;
	_ConvertCoordinate(x_handle, y_handle);
	IsVisible = false;
	
}

CObject::~CObject()
{
	if(_SpriteHandler)
		_SpriteHandler->Release();
}

void CObject::Init(LPDIRECT3DDEVICE9 d3dDevice)
{
	
}

void CObject::Update(int DeltaTime)
{

}

void CObject::Draw()
{

}

void CObject::SetGround(float ground)
{
	_ground = ground;
}

RECT CObject::GetBounds()
{
	_bounds.left = (long)x_handle;
	_bounds.right = (long)_bounds.left + _current_frame_width;
	_bounds.top = (long)y_handle;
	_bounds.bottom = (long)_bounds.top + _current_frame_height;

	return _bounds;
}

void CObject::_ConvertCoordinate(float XHandle, float YHandle)
{
	_x_draw = XHandle;

	if(YHandle > -100)
	{
		_y_draw = - YHandle + Config::SCREEN_HEIGHT;
	}
}

void CObject::_UpdatePosition(int t)
{
	//Tọa độ của đối tượng
	x_handle += _vx * t;
	y_handle += _vy * t;

	//Chuyển trục tọa độ OXY
	_ConvertCoordinate(x_handle, y_handle);
}